package com.itcast.controller;

import com.itcast.domain.Admin;
import com.itcast.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Controller
@CrossOrigin
@RequestMapping("/admin")
public class AdminController {
    @Autowired
    private AdminService adminService;

    /**
     * 注册
     * @param admin
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/register", produces = "application/json;charset=utf-8")
    @ResponseBody
    public String register(@RequestBody Admin admin) throws Exception {
        return adminService.register(admin);
    }

    /**
     * 登录
     * @param admin
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/login", produces = "application/json;charset=utf-8")
    @ResponseBody
    public String login(@RequestBody Admin admin) throws Exception {
        return adminService.login(admin);
    }

    /**
     * 查询所有管理员
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/findAll", produces = "application/json;charset=utf-8")
    @ResponseBody
    public List<Admin> findAll() {
        return adminService.findAll();
    }

    /**
     * 通过id删除管理员
     * @param id
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/deleteAdmin/{id}", produces = "application/json;charset=utf-8")
    @ResponseBody
    public String deleteAdmin(@PathVariable("id") String id) throws Exception {
        return adminService.deleteAdmin(id);
    }

}
